package com.qf;

import com.qf.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author 郗昊天
 * @version 1.0
 * @package com.qf.simple
 * @date 2022/10/14 20:34
 */
public class Sender {

    private static final String EXCHANGENAME="springbootfanout04";
    public static void main(String[] args) throws Exception {
        //获取连接
        Connection connection = ConnectionUtils.getconnection();
        //创建通道
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare(EXCHANGENAME, "fanout");
        //发送消息
        String msg="贺小倩喊你回家吃饭";
        for (int i = 0; i < 50; i++) {
            channel.basicPublish(EXCHANGENAME, "", null, (msg+i).getBytes());
        }

        //用不到就是关闭
        channel.close();
        connection.close();

    }
}
